home *** CD-ROM | disk | FTP | other *** search
- unit HVDumpExceptToFile;
-
- interface
-
- implementation
-
- uses
- HVEST,
- HVYAST32,
- Windows,
- SysUtils,
- Forms,
- LiPrgInt;
-
- type
- TAppExceptionHandler = class(TObject)
- private
- procedure AppException(Sender: TObject; E: Exception);
- end;
-
- function StackDumpStr: string;
- var
- i: integer;
- LocInfo: TLocInfo;
- begin
- Result := '';
- if not RTLIAvailable then
- Result := '(NO RTLI AVAILABLE!)'#13#10;
-
- if ESTRaw
- then Result := Result + 'Stack trace (raw):'#13#10
- else Result := Result + 'Stack trace:'#13#10;
-
- Result := Result + 'Physical Logical Unit (######) Routine';
- for i := 0 to StackDumpCount-1 do
- with StackDump[i] do
- begin
- GetLocationInfo(Pointer(CallerAdr), LocInfo);
- if LocInfo.liLineNo <> 0 then
- Result := Format('%s'#13#10'%.8x %.8x %20s (%5d) %s.%s',
- [Result, DWORD(CallerAdr), PhysicalToLogical(DWORD(CallerAdr)),
- LocInfo.liFileName, LocInfo.liLineNo, LocInfo.liUnitName, LocInfo.liPubSym1Name])
- else
- Result := Format('%s'#13#10'%.8x %.8x %s.%s',
- [Result, DWORD(CallerAdr), PhysicalToLogical(DWORD(CallerAdr)),
- LocInfo.liUnitName, LocInfo.liPubSym1Name]);
- end;
- end;
-
- procedure TAppExceptionHandler.AppException(Sender: TObject; E: Exception);
- var
- F: System.Text;
- LogFileName: string;
- begin
- {$I-} { Make sure we don't raise any EInOutError exceptions in here... }
- LogFileName := SysUtils.ChangeFileExt(System.ParamStr(0), '.EST');
- System.Assign(F, LogFileName);
- System.Append(F);
- if IOResult <> 0 then
- System.Rewrite(F);
- try
- System.Writeln(F);
- System.Writeln(F, DateTimeToStr(Now));
- System.Writeln(F, 'Exception: ', E.ClassName);
- System.Writeln(F, 'In ', ParamStr(0));
- System.Writeln(F, E.Message);
- System.Writeln(F, StackDumpStr);
- if IOResult <> 0 then ;
- finally
- System.Close(F);
- if IOResult <> 0 then ;
- end;
- E.Message := E.Message + #10#13'The exception has been logged in '+LogFileName;
- Application.ShowException(E);
- end;
-
- var
- AppExceptionHandler : TAppExceptionHandler;
-
- initialization
- AppExceptionHandler := TAppExceptionHandler.Create;
- Application.OnException := AppExceptionHandler.AppException;
-
- finalization
- AppExceptionHandler.Free;
- AppExceptionHandler := nil;
-
- end.
-